package com.itheima.tliasproject.controller;


import com.itheima.tliasproject.mapper.EmpMapper;
import com.itheima.tliasproject.pojo.*;
import com.itheima.tliasproject.service.EmpService;
import com.itheima.tliasproject.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
public class EmpController {
    @Autowired
    private EmpService empService;
    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentService studentService;

//    @GetMapping("/emps/list")
//    public Result list(){
//        List<Emp> List = empService.List();
//        log.info("查询全部数据成功",List);
//        return Result.Success(List);
//    }

    //分页查询
    @GetMapping("/emps")
    public Result page(EmpQueryParam param){
       PageResult pageResult = empService.page(param);
        log.info("分页参数 {}，{}",param.getPage(),param.getPageSize());
        log.info("查询数据{}",param);
        return Result.Success(pageResult);
    }

    //新增员工
    @PostMapping("/emps")
    public Result Save(@RequestBody Emp emp){
        empService.save(emp);
        log.info("获取到的参数是：{}" ,emp);
        return Result.Success();
    }

    //删除员工()可以通过集合来接受前端传递的参数或者是集合
    @DeleteMapping("/emps")
    public Result Delete(@RequestParam List<Integer> ids){
        log.info("接收到的参数是 {}",ids);
        empService.Delete(ids);
        return Result.Success();
    }

    //修改员工，对于修改员工都会有两步操作，查询回显，修改
    //1.查询回显
    @GetMapping("/emps/{id}")
    public Result SelectById(@PathVariable Integer id){
        log.info("接收到的id参数是：{}",id);
        Emp emp= empService.SelectById(id);
        return Result.Success(emp);
    }

    //修改员工
    @PutMapping("/emps")
    public Result update(@RequestBody Emp emp){
        log.info("接收到的数据是{}",emp);
        empService.updata(emp);
        return Result.Success();
    }

    //查询全部员工信息
    @GetMapping("/emps/list")
    public Result getalllist(){
        List<Emp> empList = empService.findall();
        return Result.Success(empList);
    }



    //员工性别统计
    @GetMapping("/report/empGenderData")
    public Result Selectgender() {
        List<InformationCount> genderStats = empService.selectgender();
        return Result.Success(genderStats);
    }

    //学员信息统计
    @GetMapping("/report/studentDegreeData")
    public Result Studentinfo() {

        List<InformationCount> stuinfo = empService.empService();
        return Result.Success(stuinfo);
    }



//员工职位人数统计
    @GetMapping("/report/empJobData")
    public Result jobList() {
        JobOption jobOption = empService.joblist();
        log.info("查询员工职位信息成功，职位数量：{}", jobOption.getJobList().length);
        return Result.Success(jobOption);
    }

}
